// router.js
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import utils from "@/utils/utils.js"

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	let path = to.path
	// 登录类页面都不做鉴权
	if (path.match(/login/)) {
		next()
		return
	}
	// 门店校验
	if (path.match(/store/)) {
		checkAuthStore(to, from, next)
	} else {
		next()
	}
});
// 全局路由后置守卫
router.afterEach((to, from) => {
	console.log('跳转结束')
})

function checkAuthStore(to, from, next) {
	let storeToken = utils.storage.get('store_token')
	if (!storeToken) {
		utils.toast('请先登录')
		next('/pages/store/login/login')
		// next()
	} else {
		next()
	}
}
export {
	router,
	RouterMount
}
